package ltd.dujiabao.reserver.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;


/**
 * @author : DuJiabao
 * @Project : reserver
 * @Time : 2021/11/5 21:37
 * @Desc :
 */
public class FileUtils {
    /**
     * 将输入流，保存为本地文件
     *
     * @param inputStream 输入流
     * @param target      目标路径
     */
    public static void saveFile(InputStream inputStream, Path target) {
        try {
            Files.copy(inputStream, target, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * @param inputStream 输入流
     * @param targetPath  目标路径
     */
    public static void saveFile(InputStream inputStream, String targetPath) {
        saveFile(inputStream, Paths.get(targetPath));
    }
}
